home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug190 / pop.c < prev    next >
Text File  |  1985-11-14  |  17KB  |  807 lines

  1. /******************************************************************
  2.     pop.c, the operand field parser...
  3. */
  4.  
  5. /*        (C) Copyright 1982 Steve Passe        */
  6. /*        All Rights Reserved                    */
  7.  
  8. /* version 1.00 */
  9. /* created 11/8/82 */
  10.  
  11. /* version 1.01
  12.  
  13.     8/30/83    modified for Aztec ver. 1.05g    smp
  14.     12/23/83 modified '*' to evaluate according to rorg smp
  15.  
  16. */
  17.  
  18. /* begincode */
  19.  
  20. /* includes */
  21.  
  22. #define AZTECZII 1
  23.  
  24. #ifndef AZTECZII
  25. #include <stdio.h>
  26. #else
  27. #include "stdio.h"                                /* with aztecII compiler */
  28. #endif
  29.  
  30. #include "b:as68.h"
  31.  
  32. #define RTERM        0x0100
  33. #define SLASH        0x0101
  34. #define HYPHEN        0x0102
  35.  
  36. #define PC_VALUE    0x0103
  37. #define IMD            0x0104
  38. #define COMMA        0x0105
  39. #define POINT        0x0106
  40. #define VALUE        0x0107
  41. #define LVALUE        0x0108
  42. #define FWRD_REF     0x0109
  43.  
  44. #define TOP            0x0200
  45. #define BOTTOM        0x0201
  46. #define LP            0x0202
  47. #define RP            0x0203
  48. #define PLUS        0x0204
  49. #define MINUS        0x0205
  50. #define MULT        0x0206
  51. #define DIV            0x0207
  52. #define LAND        0x0208
  53. #define LOR            0x0209
  54. #define LSHIFT        0x020a
  55. #define RSHIFT        0x020b
  56. #define NEGATE        0x020c
  57. #define LIM_C        1
  58. #define LM_C        2
  59. #define RXP            0x0303            /* signals a forced short address */
  60.  
  61. /* externals */
  62.  
  63. extern struct _oprnd op1, op2;            /* structs to hold operand val */
  64. extern struct _symbol *symtbl;
  65. extern char pass;
  66. extern long loc_counter;
  67. extern FLAG abs_long;                    /* default to absolute long add.*/
  68. extern FLAG rorg;
  69. extern char statement[STMNT_SIZE];        /* statement line buffer */
  70. extern char *opfld_ptr;
  71. extern long lex_val;
  72. extern char *p;
  73. static FLAG lv;
  74.  
  75. unsigned reg_num;
  76. int last_typ;
  77.  
  78. long val_stk[10] = {0L};
  79. int oprtr_stk[10] = {BOTTOM};
  80. int val_sp;
  81. int oprtr_sp;
  82.  
  83. op_eval(op)
  84. struct _oprnd *op;
  85. {
  86. /**    register int r; */
  87.     int shorty = NULL;                    /* force short address this line */
  88.     long val_push();
  89.  
  90.     op->_long_val = op->_inxl = op->_rel_lbl = NULL;
  91.     op->_typ = last_typ = NULL;
  92.     op->_regtyp = op->_iregtyp = op->_reg = op->_ireg = NULL;
  93.     oprtr_sp = val_sp = 0;
  94.     reg_num = NULL;
  95.     switch (*opfld_ptr) {
  96.     case '\t':
  97.     case '\n':
  98.     case ' ':
  99.     case NULL:
  100.         return (op->_typ = _none);
  101.     case ',':
  102.         ++opfld_ptr;
  103.     }
  104. top:
  105.     switch (/**r =**/ op_scan(op)) {
  106.     case COMMA:
  107.     case NULL:                /* determine operand type, finalize values in op */
  108.         reduce(TOP);        /* get into one value */
  109.         switch (op->_typ) {
  110.         case _imd:
  111.             op->_data = val_stk[1];
  112.             return _imd;
  113.         case _reglst:
  114.             return _reglst;
  115.         default:
  116.             if (abs_long) op->_long_val = TRUE;
  117.             if (shorty) op->_long_val = FALSE;    /* shorty overrides abs_long
  118.                                             AND long values in expression */
  119.             op->_addr = val_stk[1];
  120.             if (!op->_long_val && pass == 2) { /* pass 2/short, check range */
  121.                 if (op->_addr & ~0xffff) {
  122.                     op->_addr = 0;
  123.                     return (op->_typ = LBL_RANGE);
  124.                 }
  125.             }
  126.             return (op->_typ = _address);
  127.         }
  128.     case PLUS:
  129.         reduce(PLUS);
  130.         break;
  131.     case MINUS:
  132.         reduce(MINUS);
  133.         break;
  134.     case MULT:
  135.         reduce(MULT);
  136.         break;
  137.     case DIV:
  138.         reduce(DIV);
  139.         break;
  140.     case LAND:
  141.         reduce(LAND);
  142.         break;
  143.     case LOR:
  144.         reduce(LOR);
  145.         break;
  146.     case LSHIFT:
  147.         reduce(LSHIFT);
  148.         break;
  149.     case RSHIFT:
  150.         reduce(RSHIFT);
  151.         break;
  152.     case NEGATE:
  153.         reduce(NEGATE);
  154.         break;
  155.     case RXP:
  156.         reduce(RP);
  157.         if (val_sp != 1) return (op->_typ = OPRND_EVAL);
  158.         shorty = TRUE;
  159.         break;
  160.     case RP:
  161.         reduce(RP);
  162.         break;
  163.     case LP:
  164.         oprtr_push(LP);
  165.         break;
  166.     case PC_VALUE:
  167.         if (rorg) op->_rel_lbl = TRUE;
  168.         val_push(loc_counter);
  169.         break;
  170.     case IMD:
  171.         op->_typ = _imd;
  172.         break;
  173.     case LVALUE:
  174.         op->_long_val = TRUE;
  175.     case VALUE:
  176.         val_push(lex_val);
  177.         break;
  178.     case FWRD_REF:
  179. /** op->_forward = TRUE; ? */
  180.         val_push(lex_val);
  181.         break;
  182.     case _an:
  183.         return (op->_typ = _an);
  184.     case _dn:
  185.         return (op->_typ = _dn);
  186.     case _pd_ani:
  187.         return (op->_typ = _pd_ani);
  188.     case _ani_pi:
  189.         return (op->_typ = _ani_pi);
  190.     case _ani:
  191.         if (val_sp == 0) {
  192.             return (op->_typ = _ani);
  193.         }
  194.         if (reduce(TOP) != 1) return (op->_typ = OPRND_EVAL);
  195.         op->_displ = val_stk[1];
  196.         return (op->_typ = _d16_ani);
  197.     case _pc:
  198.         if (reduce(TOP) != 1) return (op->_typ = OPRND_EVAL);
  199.         op->_displ = val_stk[1];
  200.         return (op->_typ = (op->_iregtyp ? _labeli : _label));
  201. /**        return (op->_typ = _labeli); **/
  202.     case _an_inx:
  203.         if (reduce(TOP) != 1) return (op->_typ = OPRND_EVAL);
  204.         op->_displ = val_stk[1];
  205.         return (op->_typ = _d8_anx);
  206.     case _ccr:        return (op->_typ = _ccr);
  207.     case _sr:        return (op->_typ = _sr);
  208.     case _usp:        return (op->_typ = _usp);
  209.     case _reglst:    return (op->_typ = _reglst);
  210.  
  211.     case ERROR:
  212.     default:
  213.         return (op->_typ = OPRND_EVAL);
  214.     }
  215.     goto top;
  216. }
  217.  
  218. reduce(tkn)
  219. int tkn;
  220. {
  221.     long val_push(), val_pop();
  222.     long temp;
  223.  
  224.     while (oprtr_stk[oprtr_sp] >= (tkn & ~1)) {
  225.         switch (oprtr_stk[oprtr_sp--]) {
  226.         case PLUS:
  227.             val_push(val_pop() + val_pop());
  228.             continue;
  229.         case MINUS:
  230.             temp = val_pop();
  231.             val_push(val_pop() - temp);
  232.             continue;
  233.         case MULT:
  234.             val_push(val_pop() * val_pop());
  235.             continue;
  236.         case DIV:
  237.             temp = val_pop();
  238.             val_push(val_pop() / temp);
  239.             continue;
  240.         case LAND:
  241.             val_push(val_pop() & val_pop());
  242.             continue;
  243.         case LOR:
  244.             val_push(val_pop() | val_pop());
  245.             continue;
  246.         case LSHIFT:
  247.             temp = val_pop();
  248.             val_push(val_pop() << temp);
  249.             continue;
  250.         case RSHIFT:
  251.             temp = val_pop();
  252.             val_push(val_pop() >> temp);
  253.             continue;
  254.         case NEGATE:
  255.             val_push(-1 * val_pop());
  256.             continue;
  257.         case LP :
  258.             return val_sp;
  259.         case BOTTOM:
  260.             ++oprtr_sp;
  261.             return val_sp;
  262.         }
  263.     }
  264.     oprtr_push(tkn);
  265.     return val_sp;
  266. }
  267.  
  268. long
  269. val_push(l)
  270. long l;
  271. {
  272.     return (val_stk[++val_sp] = l);
  273. }
  274.  
  275. long
  276. val_pop()
  277. {
  278.     return (val_stk[val_sp--]);
  279. }
  280.  
  281. oprtr_push(t)
  282. int t;
  283. {
  284.     return (oprtr_stk[++oprtr_sp] = t);
  285. }
  286.  
  287. oprtr_pop()
  288. {
  289.     return (oprtr_stk[oprtr_sp--]);
  290. }
  291.  
  292. op_scan(op)
  293. struct _oprnd *op;
  294. {
  295.     int typ, len;
  296.     char s[32];
  297.     long _dtol(), _htol(), _btol(), _actol();
  298.  
  299.     p = opfld_ptr;
  300.  
  301.     if (typ = reg_scan(op)) {
  302.         opfld_ptr = p;
  303.         if (typ > 0) return typ;
  304.         goto foops;
  305.     }
  306.     switch (*opfld_ptr++) {
  307.     case '-':    /* choose between NEGATE and MINUS */
  308.         switch (last_typ) {
  309.         case NULL:
  310.         case IMD:
  311.         case LP:
  312.         case PLUS:
  313.         case MINUS:
  314.         case MULT:
  315.         case DIV:
  316.         case LAND:
  317.         case LOR:
  318.             return (last_typ = NEGATE);
  319.         case RXP:
  320.         case LSHIFT:
  321.         case RSHIFT:
  322.             goto foops;
  323.         default:
  324.             return (last_typ = MINUS);
  325.         }
  326.     case '(':                                        /* (            */
  327.         return (last_typ = LP);
  328.     case ')':                                        /* )            */
  329.         if (opfld_ptr[0] == '.'                        /* ).s            */
  330.             && (opfld_ptr[1] == 's' || opfld_ptr[1] == 'S')) {
  331.             p = (opfld_ptr += 2);        /* skip the '.s' */
  332.             return (last_typ = RXP);
  333.         }
  334.         else return (last_typ = RP);
  335.     case '#':                                        /* #            */
  336.         return (last_typ = IMD);
  337.     case '$':                                        /* $            */
  338.         lex_val = _htol();
  339.         return (last_typ = (lv) ? LVALUE : VALUE);
  340.     case '%':                                        /* %            */
  341.         lex_val = _btol();
  342.         return (last_typ = VALUE);
  343.     case '*':                                        /* *            */
  344.         switch (last_typ) {
  345.         case NULL:
  346.         case IMD:
  347.         case LP:
  348.         case PLUS:
  349.         case MINUS:
  350.         case MULT:
  351.         case DIV:
  352.         case IMD:
  353.         case LAND:
  354.         case LOR:
  355.         case LSHIFT:
  356.         case RSHIFT:
  357.             return (last_typ = PC_VALUE);
  358.         case RXP: goto foops;
  359.         default:
  360.             return (last_typ = MULT);
  361.         }
  362.     case '/':                                        /* /            */
  363.         return (last_typ = DIV);
  364.     case '+':                                        /* +            */
  365.         return (last_typ = PLUS);
  366.     case '&':                                        /* &            */
  367.         return (last_typ = LAND);
  368.     case '!':                                        /* !            */
  369.         return (last_typ = LOR);
  370.     case '>':                                        /* >...            */
  371.         if (*opfld_ptr++ != '>') goto foops;        /* >FAIL        */
  372.         return (last_typ = RSHIFT);                    /* >>            */
  373.     case '<':                                        /* <...            */
  374.         if (*opfld_ptr++ != '<') goto foops;        /* <FAIL        */
  375.         return (last_typ = LSHIFT);                    /* <<            */
  376.     case '\'':                                        /* '            */
  377.         lex_val = _actol();
  378.         return (last_typ = VALUE);
  379.     case ',':                                        /* ,            */
  380.         return (last_typ = COMMA);
  381.     case ' ':
  382.     case '\t':
  383.     case '\n':
  384.         --opfld_ptr;
  385.         return (last_typ = NULL);
  386.     }
  387.     --opfld_ptr;
  388.  
  389. /* look for decimal number */
  390.     if (*opfld_ptr >= '0' && *opfld_ptr <= '9') {
  391.         lex_val = _dtol();
  392.         return (last_typ = (lv) ? LVALUE : VALUE);
  393.     }
  394.     p = opfld_ptr;
  395.     if (nextc(&p) == LIM_C) {                            /* look for symbol...*/
  396.         len = 1;
  397.         while ((typ = nextc(&p)) == LIM_C || typ == LM_C) ++len;
  398.         savefield(opfld_ptr, len, s);
  399.         opfld_ptr = p - 1; /* back up from failure char */
  400.         if (typ = symsearch(s)) {
  401.             lex_val = symtbl[typ]._val;
  402.             if (symtbl[typ]._atr & RELOCATABLE) op->_rel_lbl = TRUE;
  403.             return (last_typ = (lex_val > 32767L || lex_val < -32768L) ?
  404.                                     LVALUE : VALUE);
  405.         }
  406.         lex_val = 0;
  407.         return (last_typ = (pass == 1) ? FWRD_REF : UNDEF_SYMBOL);
  408.     }
  409.  
  410.     ++opfld_ptr;
  411.  
  412. foops:    /* try to align on next operand arg */
  413.     --opfld_ptr;
  414.     while ((*opfld_ptr != ',') && (*opfld_ptr != '\t')
  415.             && (*opfld_ptr != '\n') && (*opfld_ptr != ' ')) {
  416.         ++opfld_ptr;
  417.     }
  418.     return (last_typ = ERROR);
  419. }
  420.  
  421. reg_scan(op)
  422. struct _oprnd *op;
  423. {
  424.     p = opfld_ptr;
  425.  
  426.     while (TRUE) {
  427.         switch (*p++) {
  428.         case '-':                                        /* -...            */
  429.             if (*p++ != '(') return NULL;
  430.             switch (reg_name()) {
  431.             case NULL:    return NULL;
  432.             case _an:                                    /* -(an...        */
  433.                 if (*p++ != ')') return ERROR;
  434.                 op->_reg = reg_num;
  435.                 op->_regtyp = 'a';
  436.                 return _pd_ani;                            /* -(an)        */
  437.             default: return ERROR;                        /* -(FAIL        */
  438.             }
  439.         case '(':                                        /* (...            */
  440.             switch (reg_name()) {
  441.             case NULL:    return NULL;
  442.             case _an:                                    /* (an...        */
  443.                 op->_reg = reg_num;
  444.                 op->_regtyp = 'a';
  445.                 switch (*p++) {
  446.                 case ')':                                /* (an)...        */
  447.                     if (*p == '+') {                    /* (an)+        */
  448.                         ++p;
  449.                         return _ani_pi;
  450.                     }
  451.                     return _ani;                        /* (an)            */
  452.                 case ',':
  453.                     goto index;            /* look for index reg */
  454.                 default: return ERROR;
  455.                 }
  456.             case _pc:                                    /* (pc...        */
  457.                 op->_reg = 8;    /* special case of addr. reg. */
  458.                 op->_regtyp = 'p';
  459.                 switch (*p++) {
  460.                 case ')':                                /* (pc)            */
  461.                     return _pc;
  462.                 case ',':
  463. index:                switch (reg_name()) {    /* look for index reg. */
  464.                     case _dn:                            /* (an/pc,dn...        */
  465.                     case _dnw:                            /* (an/pc,dn.w...    */
  466.                         op->_iregtyp = 'd';
  467.                         op->_inxl = FALSE;
  468.                         break;
  469.                     case _dnl:                            /* (an/pc,dn.l...    */
  470.                         op->_iregtyp = 'd';
  471.                         op->_inxl = TRUE;
  472.                         break;
  473.                     case _an:                            /* (an/pc,an...        */
  474.                     case _anw:                            /* (an/pc,an.w...    */
  475.                         op->_iregtyp = 'a';
  476.                         op->_inxl = FALSE;
  477.                         break;
  478.                     case _anl:                            /* (an/pc,an.l...    */
  479.                         op->_iregtyp = 'a';
  480.                         op->_inxl = TRUE;
  481.                         break;
  482.                     default:
  483.                         return ERROR;
  484.                     }
  485.                     if (*p++ != ')') return ERROR;
  486.                     op->_ireg = reg_num;
  487.                     return (op->_regtyp == 'a') ? _an_inx : _pc;
  488.                     break;
  489.                 default: return ERROR;
  490.                 }
  491.             default: return ERROR;
  492.             }
  493.         default: break;        /* neither '-' or '(' */
  494.         }
  495.         --p;
  496.         switch (reg_name()) {
  497.         case NULL:
  498.             return NULL;
  499.         case _an:
  500.             op->_reg = reg_num;
  501.             op->_regtyp = 'a';
  502.             return _an;
  503.         case _dn:
  504.             op->_reg = reg_num;
  505.             op->_regtyp = 'd';
  506.             return _dn;
  507.         case _ccr:
  508.             op->_regtyp = 'c';
  509.             return _ccr;
  510.         case _sr:
  511.             op->_regtyp = 's';
  512.             return _sr;
  513.         case _usp:
  514.             op->_regtyp = 'u';
  515.             return _usp;
  516.         case _reglst:
  517.             op->_reg_list = reg_num;
  518.             return _reglst;
  519.         case ERROR:
  520.         default:
  521.             ++p;        /* foops will backtrack...*/
  522.             return ERROR;
  523.         }
  524.     }
  525. }
  526.  
  527.  
  528. reg_name()
  529. {
  530.     int m_offset = 0;
  531.     FLAG list = FALSE;
  532.     unsigned mask = 0x0001;
  533.  
  534. top:
  535.     switch (*p) {
  536.     case 'a':                                        /* a...            */
  537.     case 'A':
  538.         m_offset = 8;
  539.     case 'd':                                        /* d...            */
  540.     case 'D':
  541.         if (p[1] < '0' || p[1] > '7') return (list) ? ERROR : NULL;
  542.         switch (term_char(p[2])) {
  543.         case RTERM:                                    /* xn            */
  544.             p += 2;
  545.             if (list) {
  546.                 reg_num |= mask << ((*(p - 1) - '0') + m_offset);
  547.                 return _reglst;
  548.             }
  549.             reg_num = *(p - 1) -'0';
  550.             return (m_offset) ? _an : _dn;
  551.         case SLASH:                                    /* xn/...        */
  552.             list = TRUE;
  553.             reg_num |= mask << ((p[1] - '0') + m_offset);
  554.             p += 3;
  555.             goto top;
  556.         case HYPHEN:                                /* xn-...        */
  557.             list = TRUE;
  558.             switch (reg_range()) {
  559.             case NULL:                                /* xn-xn        */
  560.                 p += 5;
  561.                 return _reglst;
  562.             case _reglst:                            /* xn-xn/...    */
  563.                 p += 6;
  564.                 goto top;
  565.             case ERROR:                                /* xn-xnFAIL    */
  566.                 return ERROR;
  567.             }
  568.         case POINT:                                    /* xn....        */
  569.             reg_num = p[1] - '0';
  570.             p += 4;
  571.             switch (*(p - 1)) {
  572.             case 'l':                                /* xn.l...        */
  573.             case 'L':
  574.                 return (m_offset) ? _anl : _dnl;
  575.             case 'w':                                /* xn.w...        */
  576.             case 'W':
  577.                 return (m_offset) ? _anw : _dnw;
  578.             default:                                /* xn.FAIL        */
  579.                 return ERROR;
  580.             }
  581.         default:    return (list) ? ERROR : NULL;    /* xnFAIL        */
  582.         }
  583.     case 'c':                                        /* c...            */
  584.     case 'C':
  585.         if (p[1] != 'c' && p[1] != 'C') return NULL;/* cFAIL        */
  586.         if (p[2] != 'r' && p[2] != 'R') return NULL;/* ccFAIL        */
  587.         switch (term_char(p[3])) {
  588.         case RTERM:                                    /* ccr            */
  589.             p += 3;
  590.             return (list) ? ERROR : _ccr;
  591.         case SLASH: return ERROR;                    /* ccrFAIL        */
  592.         default:    return (list) ? ERROR : NULL;    /* ccrFAIL        */
  593.         }
  594.     case 's':                                        /* s...            */
  595.     case 'S':
  596.         switch (p[1]) {
  597.         case 'r':                                    /* sr...        */
  598.         case 'R':
  599.             switch (term_char(p[2])) {
  600.             case RTERM:                                /* sr            */
  601.                 p += 2;
  602.                 return (list) ? ERROR : _sr;
  603.             case SLASH: return ERROR;                /* srFAIL        */
  604.             default:    return (list) ? ERROR : NULL;/* srFAIL        */
  605.             }
  606.         case 'p':                                    /* sp...        */
  607.         case 'P':
  608.             switch (term_char(p[2])) {
  609.             case RTERM:                                /* sp            */
  610.                 p += 2;
  611.                 if (list) {
  612.                     reg_num |= 0x8000;
  613.                     return _reglst;
  614.                 }
  615.                 reg_num = 7;
  616.                 return _an;
  617.             case SLASH:                                /* sp/...        */
  618.                 list = TRUE;
  619.                 reg_num |= 0x8000;
  620.                 p += 3;
  621.                 goto top;
  622.             default:    return (list) ? ERROR : NULL;/* spFAIL        */
  623.             }
  624.         }
  625.     case 'u':                                        /* u...            */
  626.     case 'U':
  627.         if (p[1] != 's' && p[1] != 'S') return NULL;/* uFAIL        */
  628.         if (p[2] != 'p' && p[2] != 'P') return NULL;/* usFAIL        */
  629.         switch (term_char(p[3])) {
  630.         case RTERM:                                    /* usp            */
  631.             p += 3;
  632.             return (list) ? ERROR : _usp;
  633.         case SLASH: return ERROR;                    /* uspFAIL        */
  634.         default:    return (list) ? ERROR : NULL;    /* uspFAIL        */
  635.         }
  636.     case 'p':
  637.     case 'P':
  638.         if (p[1] != 'c' && p[1] != 'C') return NULL;/* pFAIL        */
  639.         switch (term_char(p[2])) {
  640.         case RTERM:                                    /* pc            */
  641.             p += 2;
  642.             return (list) ? ERROR : _pc;
  643.         case SLASH: return ERROR;                    /* pcFAIL        */
  644.         default:    return (list) ? ERROR : NULL;    /* pcFAIL        */
  645.         }
  646.     default:                                        /* FAIL            */
  647.         return NULL;
  648.     }
  649. }
  650.  
  651. term_char(c)
  652. char c;
  653. {
  654.     switch (c) {
  655.     case ')':
  656.     case '\t':
  657.     case ',':
  658.     case '\n':
  659.     case ' ':
  660.         return RTERM;
  661.     case '.':
  662.         return POINT;
  663.     case '/':
  664.         return SLASH;
  665.     case '-':
  666.         return HYPHEN;
  667.     default:
  668.         return NULL;
  669.     }
  670. }
  671.  
  672. reg_range()
  673. {
  674.     int start, stop;
  675.     unsigned mask = 0x0001;
  676.  
  677.     if (p[0] != p[3]) return ERROR;
  678.     if ((p[4] < '0') || (p[4] > '7')) return ERROR;
  679.     start = p[1] - '0';
  680.     if ((p[4] - '0') < start) {
  681.         stop = start;
  682.         start = p[4] - '0';
  683.     }
  684.     else stop = p[4] - '0';
  685.     if (p[0] == 'a'  || p[0] == 'A') {
  686.         start += 8;
  687.         stop += 8;
  688.     }
  689.     for ( ; start <= stop; ++start) {
  690. /**        reg_num |= mask << start; */
  691. /** aztec has problems... */
  692.         if (start) reg_num |= mask << start;
  693.         else reg_num |= mask;
  694.     }
  695.     switch (term_char(p[5])) {
  696.     case RTERM:
  697.         return NULL;
  698.     case SLASH:
  699.         return _reglst;
  700.     case HYPHEN:
  701.         return ERROR;
  702.     }
  703. }
  704.  
  705. long
  706. _dtol()
  707. {
  708.     long val = 0L;
  709.     register char c, x = 0;
  710.  
  711.     while ((c = *opfld_ptr++) >= '0' && c <= '9') {
  712.         val = val * 10 + c - '0';
  713.         ++x;
  714.     }
  715.     lv = (x > 5) ? YES : NO;
  716.     --opfld_ptr;
  717.     return val;
  718. }
  719.  
  720. long
  721. _htol()
  722. {
  723.     long val = 0L;
  724.     int i;
  725.     register char c, x = 0;
  726.  
  727.     while (TRUE) {
  728.         if ((c = *opfld_ptr++) >= '0' && c <= '9') {
  729.             i = c - '0';
  730.         }
  731.         else if ((c = tolower(c)) >= 'a' && c <= 'f') {
  732.             i = (c - 'a') + 10;
  733.         }
  734.         else {
  735.             lv = (x > 4) ? YES : NO;
  736.             --opfld_ptr;
  737.             return val;
  738.         }
  739.         val = val * 16 + i;
  740.         ++x;
  741.     }
  742. }
  743.  
  744. long
  745. _btol(s)
  746. char *s;
  747. {
  748.     long val = 0L;
  749.     char c;
  750.  
  751.     while ((c = *opfld_ptr++) >= '0' && c <= '1')
  752.         val = val * 2 + c - '0';
  753.     --opfld_ptr;
  754.     return val;
  755. }
  756.  
  757. long
  758. _actol()
  759. {
  760.     register int x;
  761.     long val = 0L;
  762.     char c;
  763.  
  764.     for (x = 4; x; --x) {
  765.         if (*opfld_ptr == '\'') {
  766.             ++opfld_ptr;                    /* pass it */
  767.             if (*opfld_ptr != '\'') {        /* end of ascii str */
  768.                 return val;
  769.             }
  770.         }
  771.         val = val * 256 + *opfld_ptr++;
  772.     }
  773.     if (*opfld_ptr != '\'') return ERROR;
  774.     ++opfld_ptr;
  775.     return val;
  776. }
  777.  
  778. /*
  779. #undef RTERM
  780. #undef SLASH
  781. #undef HYPHEN
  782. #undef PLUS
  783. #undef MINUS
  784. #undef MULT
  785. #undef DIV
  786. #undef LAND
  787. #undef LOR
  788. #undef LSHIFT
  789. #undef RSHIFT
  790. #undef NEGATE
  791. #undef PC_VALUE
  792. #undef IMD
  793. #undef LP
  794. #undef RP
  795. #undef COMMA
  796. #undef POINT
  797. #undef VALUE
  798. #undef LIM_C
  799. #undef LM_C
  800.  
  801. */
  802.  - '0';
  803.         }
  804.         else if ((c = tolower(c)) >= 'a' && c <= 'f') {
  805.             i = (c - 'a') + 10;
  806.         }
  807.         els